home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 101OA25 (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  2.1 KB  |  58 lines

  1. package com.sun.java.swing.plaf.metal;
  2.  
  3. import com.sun.java.swing.AbstractButton;
  4. import com.sun.java.swing.ButtonModel;
  5. import com.sun.java.swing.Icon;
  6. import com.sun.java.swing.JCheckBox;
  7. import com.sun.java.swing.plaf.UIResource;
  8. import java.awt.Component;
  9. import java.awt.Graphics;
  10. import java.io.Serializable;
  11.  
  12. public class MetalCheckBoxIcon implements Icon, UIResource, Serializable {
  13.    protected void drawCheck(Component c, Graphics g, int x, int y) {
  14.       int controlSize = this.getControlSize();
  15.       g.fillRect(x + 3, y + 5, 2, controlSize - 8);
  16.       g.drawLine(x + (controlSize - 4), y + 3, x + 5, y + (controlSize - 6));
  17.       g.drawLine(x + (controlSize - 4), y + 4, x + 5, y + (controlSize - 5));
  18.    }
  19.  
  20.    protected int getControlSize() {
  21.       return 13;
  22.    }
  23.  
  24.    public int getIconHeight() {
  25.       return this.getControlSize();
  26.    }
  27.  
  28.    public int getIconWidth() {
  29.       return this.getControlSize();
  30.    }
  31.  
  32.    public void paintIcon(Component c, Graphics g, int x, int y) {
  33.       JCheckBox cb = (JCheckBox)c;
  34.       ButtonModel model = ((AbstractButton)cb).getModel();
  35.       int controlSize = this.getControlSize();
  36.       model.isSelected();
  37.       if (model.isEnabled()) {
  38.          if (model.isPressed() && model.isArmed()) {
  39.             g.setColor(MetalLookAndFeel.getControlShadow());
  40.             g.fillRect(x, y, controlSize - 1, controlSize - 1);
  41.             MetalUtils.drawPressed3DBorder(g, x, y, controlSize, controlSize);
  42.          } else {
  43.             MetalUtils.drawFlush3DBorder(g, x, y, controlSize, controlSize);
  44.          }
  45.  
  46.          g.setColor(MetalLookAndFeel.getControlInfo());
  47.       } else {
  48.          g.setColor(MetalLookAndFeel.getControlShadow());
  49.          g.drawRect(x, y, controlSize - 1, controlSize - 1);
  50.       }
  51.  
  52.       if (model.isSelected()) {
  53.          this.drawCheck(c, g, x, y);
  54.       }
  55.  
  56.    }
  57. }
  58.